<template>
    <!-- 绑定微信提示 -->
    <div class="bind-wechat-window">
        <bind-wechat-info :isShow="showWindow === 'bindWechatInfo'" @closeWindow="closeWindow" />
    </div>
</template>

<script>
import { Dialog } from 'vant'
import { isLoginChose } from '_projectFn/login'
import { enterUserSet } from '_projectFn/page'

// 自定义组件
import BindWechatInfo from "_components/project/ShowWindow/BindWechatInfo"

export default {
    name: 'BindWechatWindow',
    props: {
        isShow: {
            type: Boolean,
            default: false,
        },
        confirmButtonText: {
            type: String,
            default: '绑定微信'
        },
        cancelButtonText: {
            type: String,
            default: '关闭'
        },
        confirmButtonColor: {
            type: String,
            default: '#0077bf'
        },
        cancelButtonColor: {
            type: String,
            default: '#999999'
        },
        title: {
            type: String,
            default: ''
        },
        message: {
            type: String,
            default: '30秒绑定微信，查看更多!\n同时为您开通微信群业务信息权限!'
        },
        closeOnClickOverlay: {
            type: Boolean,
            default: true,
        },
        className: {
            type: String,
            default: 'no-login'
        },
        width: {
            type: Number,
            default: 280,
        },
        showCancelButton: {
            type: Boolean,
            default: true,
        }
    },
    data() {
        return {
            showWindow: ''
        }
    },
    methods: {
        showBindWechatInfo() {
            // console.log('showBindWechatInfo')
            this.showWindow = 'bindWechatInfo'
        },
        closeWindow() {
            this.showWindow = ''
            this.$emit('closeBindWechatWindow')
        },
    },
    watch: {
        isShow() {
            const that = this
            if (this.isShow) {
                Dialog.alert({
                    message: this.message,
                    title: this.title,
                    confirmButtonText: this.confirmButtonText,
                    cancelButtonText: this.cancelButtonText,
                    confirmButtonColor: this.confirmButtonColor,
                    cancelButtonColor: this.cancelButtonColor,
                    closeOnClickOverlay: this.closeOnClickOverlay,
                    showCancelButton: this.showCancelButton,
                    className: this.className,
                    width: this.width,
                    beforeClose(action, done) {
                        console.log('action', action)
                        if (action === 'confirm') {
                            if (isLoginChose()) {
                                // enterUserSet('safty')
                                that.showBindWechatInfo()
                            }
                        }
                        that.$emit('closeBindWechatWindow')
                        done()
                    }
                })
            } else {
                Dialog.close()
            }
        }
    },
    deactivated() {
        this.closeWindow()
    },
    components: {
        BindWechatInfo,
    }
}
</script>

<style lang="scss">

</style>